package exam.yuewenExam;


class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
      this.val = val;
    }
}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
        this.val = val;
    }
}
public class Main {
    public static void main(String[] args) {
        Main test = new Main();
    }

    public ListNode deleteDuplicationNode (ListNode pHead) {
        // write code here
        if(pHead == null){
            return null;
        }
        ListNode dummy = new ListNode(0);
        dummy.next = pHead;
        ListNode cur = dummy;
        while (cur.next != null && cur.next.next != null){
            if(cur.next.val == cur.next.next.val){
                int val = cur.next.val;
                while (cur.next != null && cur.next.val == val){
                    cur.next = cur.next.next;
                }
            }else {
                cur = cur.next;
            }
        }
        return dummy.next;
    }

    public boolean isSubtree (TreeNode s, TreeNode t) {
        // write code here
        return dfs(s,t);
    }
    public boolean dfs(TreeNode root1,TreeNode root2){
        if(root1 == null){
            return false;
        }
        return get(root1,root2) || dfs(root1.left,root2) || dfs(root1.right,root2);
    }

    public boolean get(TreeNode root1,TreeNode root2){
        if(root1 == null && root2 == null){
            return true;
        }
        if(root1 == null || root2 == null || root1.val != root2.val){
            return false;
        }
        return get(root1.left,root2.left) && get(root1.right,root2.right);
    }
}
